package com.bw.service.lizeliang;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.support.DaoSupport;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ModelAttribute;

import com.bw.bean.Clazz;
import com.bw.bean.Interview;
import com.bw.bean.Student;
import com.bw.bean.Teacher;
import com.bw.bean.lizeliang.ClassTree;
import com.bw.bean.lizeliang.Select;
import com.bw.bean.lizeliang.ShouyeData;
import com.bw.dao.DataDao;
import com.bw.dao.InterviewDao;
import com.bw.service.InterviewService;
@Service
public class DataServiceImpl implements DataService{
	@Autowired
	private InterviewDao interviewDaoImpl;
	@Autowired
	private DataDao dataDaoImpl;

	/*public List<ShouyeData> getData(Integer tid, String sname, Integer cid, String start, String end) {
		// TODO Auto-generated method stub
		Date date = new Date();
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.DATE, -1);
		Date tom = ca.getTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String today = sdf.format(tom);
		System.err.println("tid:"+tid+"-sname:"+sname+"-cid:"+cid+"-start:"+start+"-end:"+end+"-today:"+today);
		List<ShouyeData> data = dataDaoImpl.getData(tid, sname, cid, start, end, today);
		return data;
	}*/

	public List<Clazz> getClassList(Integer tid) {
		// TODO Auto-generated method stub
		if(tid == -1){
			return dataDaoImpl.getAllClass(tid);
		}
		return dataDaoImpl.getClassList(tid);
	}

	public List<ClassTree> getClassTree(Integer tid) {
		// TODO Auto-generated method stub
		return dataDaoImpl.getClassTree(tid);
	}

	public int addInterview(Interview interview) {
		// TODO Auto-generated method stub
		if(interview.getIid()!=null){
			return interviewDaoImpl.update(interview);
		}
		return interviewDaoImpl.insertSelective(interview);
	}

	public List<ShouyeData> getData(Integer tid, String sname, Integer cid, String start, String end, String tname) {
		Date date = new Date();
		Calendar ca = Calendar.getInstance();
		ca.setTime(date);
		ca.add(Calendar.DATE, -1);
		Date tom = ca.getTime();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String today = sdf.format(tom);
		System.err.println("tid:"+tid+"-sname:"+sname+"-cid:"+cid+"-start:"+start+"-end:"+end+"-today:"+today);
		List<ShouyeData> data = dataDaoImpl.getData(tid, sname, cid, start, end, today, tname);
		return data;
	}

	public List<Teacher> getTeacherList() {
		// TODO Auto-generated method stub
		List<Teacher> teacherList = dataDaoImpl.getTeacherList();
		List<Teacher> teacherListReturn = new ArrayList<Teacher>();
		for (Teacher teacher : teacherList) {
			if(teacher.getTid()==-1){
				continue;
			}
			teacherListReturn.add(teacher);
		}		
		
		return teacherListReturn;
	}
}
